<?php

/**
 * Entité modèle : Association tag / image
 * Représente les associations entre les tags et les images
 * 
 * <b>Structure :</b>
 * <ul>
 *  <li>image_id</li>
 *	<li>tag_id</li>
 * </ul>
 * 
 * @author Cyril Souti
 * @version 1.2
 * @package models
 *
 */
class Models_Content_ImageTag extends Models_TableGite
{
	protected $_name = 'content_image_tag';
	protected $_referenceMap = array(self::REFERENCE_IMAGE => array('columns' => 'image_id','refTableClass' => Models_Content_Image::CLASS_NAME,'refColumns' => 'id'),
									 self::REFERENCE_TAG => array('columns' => 'tag_id','refTableClass' => Models_Content_Tag::CLASS_NAME,'refColumns' => 'id'));
	
	const REFERENCE_IMAGE = 'image';
	const REFERENCE_TAG = 'tag';
	const CLASS_NAME = 'Models_Content_ImageTag';
	const SQL_ORDER = 'position ASC';
	

	/**
	 * Retourne les images du tag
	 * 
	 * @param string $tag
	 * @return array(Zend_Db_Table_Row) des images
	 */
	public function getImagesOfTag($tag) {
		$tagTable = new Models_Content_Tag();
		$tagRow = $tagTable->getRowTag($tag);
		if (!is_null($tagRow)) {
			return $this->getImagesOfTagRow($tagRow);
		}
		else {
			return array();
		}
	}
	
	/**
	 * Retourne les images du tag
	 * 
	 * @param Zend_Db_Table_Row $tag
	 * @return array(Zend_Db_Table_Row) des images
	 */
	public function getImagesOfTagRow(Zend_Db_Table_Row $tagRow) {
		$select = $tagRow->select()->order(self::SQL_ORDER);
		$images = $tagRow->findManyToManyRowset(Models_Content_Image::CLASS_NAME, self::CLASS_NAME, null, null, $select);
		return $images;
	}
}